package springcloud.consume;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.web.client.RestTemplate;

@EnableEurekaClient // 本服务启动后会自动注册进eureka服务中
@SpringBootApplication
public class ConsumeApplication6210 {

    public static void main(String[] args) {
        SpringApplication.run(ConsumeApplication6210.class, args);
    }

    //@Bean 应用在方法上，用来将方法返回值设为bean
    @Bean
    @LoadBalanced  //@LoadBalanced实现负载均衡
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    // 设置@Value注解取值不到忽略（不报错）
    @Bean
    public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {
        PropertySourcesPlaceholderConfigurer c = new PropertySourcesPlaceholderConfigurer();
        c.setIgnoreUnresolvablePlaceholders(true);
        return c;
    }

    // 指定日Ribbon负载均衡策略
//    @Bean
//    public IRule myRule(){
//        return new RandomRule();
//    }
}
